/*
 * @Description: 
 * @Autor: 商晓彬
 * @Date: 2021-09-09 17:57:19
 * @LastEditors: 商晓彬
 * @LastEditTime: 2022-01-04 14:34:25
 */
import { AfterViewChecked, Component, ElementRef, EventEmitter, Injector, Input, Output, ViewChild } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { ModalDirective } from 'ngx-bootstrap';
import * as _ from 'lodash';
import { finalize } from 'rxjs/operators';
import { MessageService } from '@abp/message/message.service';
import { } from '@shared/service-proxies/service-proxies';
import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent';
import * as moment from 'moment';

@Component({
    selector: 'app-go-print',
    templateUrl: './go-print.component.html',
    styleUrls: ['./go-print.component.less']
})
export class GoPrintComponent extends AppComponentBase {
    //引入子组件
    @ViewChild('createOrEditModal') modal: ModalDirective;
    @Output() modalSave: EventEmitter<any> = new EventEmitter<any>();
    @Input() printInfo: any;//打印信息
    saving = false;
    active = false;
    constructor(
        injector: Injector,
        private _messageService: MessageService,
    ) {
        super(injector);
    }
    getPno(data) {
        let rs = [];
        let first = data.substring(0, 15);
        rs.push(first);
        let last = data.substring(15, data.length);
        rs.push(last);
        return rs;
    }
    getMateral(data) {
        let rs = [];
        if (data.length > 20) {
            let sum = data.split("|");
            if (sum[0].length <= 16) {
                rs.push(sum[0]);
                let last = '|' + sum[1] + '|' + sum[2];
                rs.push(last);
            } else {
                let first = sum[0].substring(0, 16);
                let second = sum[0].substring(16, data.length);
                let flagLength = second + '|' + sum[1] + '|' + sum[2];
                if (flagLength.length > 20) {
                    let third = flagLength.substring(0, 16);
                    let fourth = flagLength.substring(16, data.length);
                    rs.push(first);
                    rs.push(second);
                    rs.push(third);
                    rs.push(fourth);
                } else {
                    rs.push(first);
                    rs.push(second);
                }
            }
        } else {
            rs.push(data);
        }
        
        return rs;
    }
    save() {
        let msg = document.getElementById("msg");
        const WindowPrt = window.open('', '', 'left=0,top=0,width=1920,height=1080,toolbar=0,scrollbars=0,status=0');
        WindowPrt.document.write(msg.innerHTML);
        WindowPrt.document.close();
        WindowPrt.focus();
        WindowPrt.print();
        WindowPrt.close();
    }
    ngOnInit() {
    }
    //打开弹窗
    onShown(): void {
        this.active = true;
    }
    //查看新增任务
    show(): void {
        this.active = true;
        this.modal.show();
    }
    //关闭事件
    close(): void {
        //清空form表单
        this.active = false;
        this.modalSave.emit();
        this.modal.hide();
    }
}
